package com.zhuhaibaoxian.wanjiuseller.interfacewj;

import com.dou361.dialogui.DialogUIUtils;
import com.dou361.dialogui.bean.BuildBean;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zhuhaibaoxian.wanjiuseller.IView.IListView;
import com.zhuhaibaoxian.wanjiuseller.app.MyApplication;
import com.zhuhaibaoxian.wanjiuseller.bean.ReceiveListBean;
import com.zhuhaibaoxian.wanjiuseller.bean.RemarkBean;
import com.zhuhaibaoxian.wanjiuseller.bean.SureListBean;
import com.zhuhaibaoxian.wanjiuseller.retrofit.Api;
import com.zhuhaibaoxian.wanjiuseller.utils.LogUtil;
import com.zhuhaibaoxian.wanjiuseller.utils.ToastUtil;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/6/11.
 *
 */

public class GetListPresenter {
    private IListView iListView;

    public GetListPresenter(IListView iListView) {
        this.iListView = iListView;
    }

    public void getList(final XRecyclerView recyclerview, final BuildBean buildBean) {
        Api.singletonGank(MyApplication.context).getList().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ReceiveListBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(ReceiveListBean value) {
                LogUtil.e("error="+value.getCode());

                if (value!=null&&value.getCode().equals("0")) {
                    iListView.getDataSuccess(value);
                }
            }

            @Override
            public void onError(Throwable e) {
                LogUtil.e("error="+e.getMessage());
                recyclerview.refreshComplete();
                DialogUIUtils.dismiss(buildBean);
            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 确认订单
     * @param order_mun
     */
    public void sureOrder(String order_mun) {
        Api.singletonGank(MyApplication.context).sureList(order_mun).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<SureListBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(SureListBean value) {
                ToastUtil.showLong(MyApplication.context,value.getMsg());
                iListView.sureSuccess(value);
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 获取留言列表
     * @param recyclerview
     * @param buildBean
     */
    public void getRemarkList(final XRecyclerView recyclerview, final BuildBean buildBean) {
        Api.singletonGank(MyApplication.context).getRemark().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<RemarkBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(RemarkBean value) {
                LogUtil.e("error="+value.getCode());

                if (value!=null&&value.getCode().equals("0")) {
                    iListView.getRemarkSuccess(value);
                }
            }

            @Override
            public void onError(Throwable e) {
                LogUtil.e("error="+e.getMessage());
                recyclerview.refreshComplete();
                DialogUIUtils.dismiss(buildBean);
            }

            @Override
            public void onComplete() {

            }
        });
    }
}
